<?php

namespace app\index\model;

use think\Model;

class User extends Model
{
    protected function setPasswordAttr($val) {
        return md5($val);
    }
    //登陆验证
    public function loginCheck($data) {
        $data['password'] = md5($data['password']);
        $res = self::where($data)->find();
        if($res) {
            return $res;
        }else {
            return false;
        }
    }
    //注册
    public function register($data) {
        $res = self::create($data);
        if($res) {
            return true;
        }else {
            return false;
        }
    }

    //查询所有用户
    public function sel() {
        $res = self::all();
        return $res;
    }
    //删除用户
    public function del($id) {
        $user = self::get($id);
        if($user) {
            $res = $user->delete();
            return $res;
        }else {
            return false;
        }

    }
}
